// leaveDate_package/pages/teacherLeaveDate/teacherLeaveDate.ts
import {getLeaveGetList} from '../../../api/teacher/notice'
Page({

  /**
   * 页面的初始数据
   */
  data: {
   postData:{
    pageNum:1,
    pageSize:10, 
   },
   total:0, //总页数
   moreLimt:false,//是否加载完成
   isfreshComplete:false, //是否刷新完成
   historyList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
  },
      // 列表刷新课程
      loadPageEvent(data:any){
        const type = data.detail.type
        switch(type){
          case 'refresh':
            this.resetPage()
            this.reqLeaveGetList()
            this.setData({
              isfreshComplete:true
            })
            break;
           case 'load':
            let postData = this.data.postData as any
            if(postData.pageNum * postData.pageSize < this.data.total){
              postData.pageNum  = postData.pageNum + 1
              this.setData({
                postData
              })
              this.reqLeaveGetList()
            }else{
             this.setData({
              moreLimt: true
             })
            }
            break;
        }
        },
                // 重置页码
    resetPage(){
      let postData = this.data.postData as any
      postData.pageNum = 1
     this.setData({
      postData,
      historyList:[]
     })
    },
  // 查看请假调课历史记录
  toSeeHistory(){
 wx.navigateTo({
   url:"/leaveDate_package/pages/teacherLeaveDateRecord/teacherLeaveDateRecord"
 })
  },
  // 获取请假历史记录
  async reqLeaveGetList(){
    const postData = this.data.postData as any
    const {code,data:res} = await getLeaveGetList(postData)
    if(code === 200){
     const {total,list} = res
     const historyList = this.data.historyList.concat(list)
      this.setData({
        historyList,
        total
      })
    }  
  },
  // 老师前往对请假审核
  toSeeDetail(e:any){
    const {leaveid} = e.currentTarget.dataset
    const type = getApp().getUserType()
    if(type !== "01") return
    wx.navigateTo({
      url:`/leaveDate_package/pages/teacherLeaveDate/teacherLeaveDate?leaveId=${leaveid}`
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.resetPage()
    this.reqLeaveGetList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})